package com.hk.newsservice.mapper;


import com.hk.model.News;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.util.List;

/**
 * @Author: zhe
 * @Date: 2021/6/16 10:30
 * @Statement: 新闻Mapper层接口
 */
public interface NewsMapper extends BaseMapper<News> {

    @Override
    List<News> findAll(News news);

    @Override
    int count(News news);

    @Override
    News findById(Integer id);

    List<News> findByIds(@Param("id") Integer id);

    List<News> findByHits(@Param("hits") int hits);

    @Insert("insert into news value" +
            "(null,#{title},#{subhead},#{content},#{releaseDate}," +
            "#{author},#{hits},#{typeId},#{gmtCreate},#{gmtModified})")
    @Override
    int save(News news);

    @Update("update news set " +
            "title=#{title},subhead=#{subhead},content=#{content},author=#{author},type_id=#{typeId},gmt_modified=#{gmtModified}" +
            " where id = #{id} ")
    @Override
    int update(News news);

    @Update("update news set " +
            "hits = hits+1,gmt_modified=#{gmtModified}" +
            "where id = #{id} ")
    int updateHits(News news);

    @Delete("delete from news where id = #{id} ")
    @Override
    int delete(Integer id);

}
